package com.yami.shop.multishop.controller;

import com.yami.shop.bean.model.ShopSetting;
import com.yami.shop.bean.model.ShopWallet;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.ShopSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 店铺设置Controller
 */
@RestController
@RequestMapping("/shop/setting")
@Api(tags = "店铺设置接口")
@Slf4j
public class ShopSettingController {

    @Autowired
    private ShopSettingService shopSettingService;

    @GetMapping("/info")
    @ApiOperation(value = "获取店铺设置信息")
    public ResponseEntity<ShopSetting> getShopSetting(@RequestParam @ApiParam("店铺ID") Long shopId) {
        try {
            ShopSetting shopSetting = shopSettingService.getShopSetting(shopId);
            return ResponseEntity.ok(shopSetting);
        } catch (Exception e) {
            log.error("获取店铺设置信息失败", e);
            throw new YamiShopBindException("yami.no.auth");
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新店铺设置")
    public ResponseEntity<String> updateShopSetting(@Valid @RequestBody ShopSetting shopSetting) {
        try {
            shopSettingService.updateShopSetting(shopSetting);
            return ResponseEntity.ok("修改成功");
        } catch (Exception e) {
            log.error("更新店铺设置失败", e);
            return ResponseEntity.ok(e.getMessage());
        }
    }
} 